/*
 * @Author: your name
 * @Date: 2021-07-21 20:55:46
 * @LastEditTime: 2021-07-23 19:48:20
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \Self\hm-news-86\src\utils\request.js
 */
// 封装axios
import axios from 'axios'
// const { default: axios } = require('axios')

// 使用axios来创建axios的实例对象并配置
const request = axios.create({
  baseURL: 'http://toutiao.itheima.net',
  timeout: 5000
})
// 添加请求拦截器
request.interceptors.request.use(
  function(request) {
    // 再发请求前做什么
    // console.log('请求拦截器', request)
    return request
  },
  function(error) {
    console.log(error)
  }
)
// 添加响应拦截器
request.interceptors.response.use(
  function(response) {
    // 响应拦截器的response
    // console.log('响应拦截器的response', response)
    // 在接收的结果里可以少写个data
    return response.data
  },
  function(error) {
    console.log(error)
  }
)
export default request
